import { defineStore } from 'pinia'
import i18n from '@/i18n/index'
import { I18NType } from '@/app.config'

const languageHis: I18NType = (sessionStorage.getItem('language') === I18NType.EN_US  ? I18NType.EN_US : I18NType.ZH_CN) || I18NType.ZH_CN

export default defineStore('layout', {
    state: () => {
        return {
            language: languageHis as I18NType,
            mainApp: true,
        }
    },
    getters: {
        getLanguage(): I18NType{
            return this.language
        },
        getMainApp(): boolean{
            return this.mainApp   
        }
    },
    actions: {
        setLanguage(language: I18NType){
            this.language = language
            i18n.global.locale.value = language
            sessionStorage.setItem('language', language)
        }
    }
})
